package it.uniroma1.di.machinelearning;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;

import org.apache.log4j.Logger;

public class Main {

	private static Logger log = Logger.getLogger(Main.class);
	
	private static final String FILE_PATH = "C:/Users/vitalij/Documents/spazi_lavoro/weka/ensemble-methods/src/main/resources/";

	public static void main(String[] args) {
//		String name = "data.arff";
//		Path path = FileSystems.getDefault().getPath(FILE_PATH, name);
//		readLargeFileLines(name,"first100rows.txt", 100);

		StackingRunnable stacking = new StackingRunnable();
		Thread stackingThread = new Thread(stacking);
		
		DecisionTreeRunnable decisionTreeRunnable = new DecisionTreeRunnable();
		Thread decisionTreeThread = new Thread(decisionTreeRunnable);
		
		NaiveBayesRunnable naiveBayesRunnable = new NaiveBayesRunnable();
		Thread naiveBayesThread = new Thread(naiveBayesRunnable);
		
		SupportVectorRunnable supportVectorRunnable = new SupportVectorRunnable();
		Thread supportVectorThread = new Thread(supportVectorRunnable);
		
		stackingThread.start();
		decisionTreeThread.start();
		naiveBayesThread.start();
		supportVectorThread.start();
	}

	public static void readLargeFileLines(String inputFileName, String outputFileName, Integer numberOfLines) {
		try (BufferedReader reader = Files.newBufferedReader(
				FileSystems.getDefault().getPath(FILE_PATH, inputFileName), Charset.defaultCharset());) {

			try (BufferedWriter writer = Files.newBufferedWriter(
					FileSystems.getDefault().getPath(FILE_PATH, outputFileName), Charset.defaultCharset());) {
				String line = null;
				Integer lineCount = new Integer(0);
				while ((line = reader.readLine()) != null && lineCount < numberOfLines) {
					writer.write(line);
					writer.write(System.getProperty("line.separator"));
					lineCount++;
				}

			} catch (IOException ioe) {
				ioe.printStackTrace();
			}

		} catch (IOException ioe) {
			ioe.printStackTrace();
		}
	}

}
